package com.example.q_kang.hhh.setting;

import com.hjq.toast.ToastUtils;
import com.lzy.okgo.model.Response;
import com.sskj.base.BasePresenter;
import com.sskj.base.api.Constant;
import com.sskj.base.base.HttpData;
import com.sskj.base.bean.MyBanksBean;
import com.example.q_kang.hhh.api.JsonCallBack;


/**
 * @author Hey
 * Create at  2019/04/10
 */
class BindingBankPresenter extends BasePresenter<BindingBankActivity> {
    public void getBankList() {
        httpService.getBankList()
                .tag(this)
                .execute(new JsonCallBack<HttpData<MyBanksBean>>() {
                    @Override
                    public void onSuccess(Response<HttpData<MyBanksBean>> response) {
                        HttpData<MyBanksBean> body = response.body();
                        if (body.getStatus() == Constant.OK) {
                            mView.showUserBanks(body.getData().getUserBanks());
                        }

                    }

                    @Override
                    public void onFinish() {
                        super.onFinish();
                        mView.hideLoading();
                    }
                });
    }

    public void deleteBank(String opening_id) {
        httpService.deleteBank(opening_id)
                .tag(this)
                .execute(new JsonCallBack<HttpData>() {
                    @Override
                    public void onSuccess(Response<HttpData> response) {
                        HttpData body = response.body();
                        ToastUtils.show(body.getMsg());
                        if (body.getStatus() == Constant.OK) {
                            getBankList();
                        }
                    }

                    @Override
                    public void onFinish() {
                        super.onFinish();
                        mView.hideLoading();
                    }
                });
    }

    public void setBankDefault(String opening_id) {
        httpService.setBankDefault(opening_id)
                .tag(this)
                .execute(new JsonCallBack<HttpData>() {
                    @Override
                    public void onSuccess(Response<HttpData> response) {
                        HttpData body = response.body();
                        ToastUtils.show(body.getMsg());
                        if (body.getStatus() == Constant.OK) {
                            getBankList();
                        }
                    }

                    @Override
                    public void onFinish() {
                        super.onFinish();
                        mView.hideLoading();
                    }
                });
    }
}
